<script src="<?php echo $baseurl?>public/ckeditor/ckeditor.js"></script>
<script src="<?php echo $baseurl?>public/ckeditor/adapters/jquery.js"></script>
<script>
        $(document).ready( function() {
             $( "#datepicker" ).on('change', function(){
                var time = $( "#datepicker" ).val();
                var exp = time.split('/');
                var time_fix = exp[1]+'-'+exp[0]+'-'+exp[2];
                $("#datepicker").val(time_fix);
            });
        });
       
                       
</script>
<div class="breadcrumbwidget">
	<ul class="skins">
        <li><a href="default" class="skin-color default"></a></li>
        <li><a href="orange" class="skin-color orange"></a></li>
        <li>&nbsp;</li>
        <li class="fixed"><a href="" class="skin-layout fixed"></a></li>
        <li class="wide"><a href="" class="skin-layout wide"></a></li>
    </ul><!--skins-->
	<ul class="breadcrumb">
        <li><a href="<?php echo $baseurl?>">Trang chủ</a> <span class="divider">/</span></li>
        <li class="active">Thêm E-coupon</li>
    </ul>
</div><!--breadcrumbwidget-->
<div class="pagetitle">
	<h1>Thêm E-coupon</h1>
</div><!--pagetitle-->

<div class="maincontent">
<?php if(validation_errors()): ?>
    <div class="alert alert-error" style="margin: 10px 10px 10px 40px;">
      <button data-dismiss="alert" class="close" type="button">×</button>
      <?php echo validation_errors(); ?>
    </div>
<?php endif;?>
<?php if(!in_array(@$return, array(null, '', '0'))): ?>
    <div class="alert alert-error" style="margin: 10px 10px 10px 40px;">
      <button data-dismiss="alert" class="close" type="button">×</button>
      <?php if(@$return == 200): ?>
        <span>Thêm ưu đãi mới thành công!</span>
      <?php elseif(@$return == 101):?>
        <span>Ưu đãi đã tồn tại!</span>
      <?php endif;?>
    </div>
<?php endif;?>
	<div class="contentinner content-dashboard">
    
    <?php $attr = array('class' => 'stdform'); echo form_open_multipart('', $attr)?>
        <p>
        	<label>Tên E-coupon ( * )</label>
            <span class="field"><input type="text" name="title" class="input-xxlarge" placeholder="Tên E-coupon" value="<?php echo $this->input->post('title');?>"/></span>
        </p>
        <p>
        	<label>Số tiền giảm giá ( * )</label>
            <span class="field"><input type="number" name="sale_off" class="input-xlarge" placeholder="Số tiền giảm giá" value="<?php echo $this->input->post('sale_off');?>"/></span>
        </p>
        <p>
        	<label>Điều kiện sử dụng<br><span style="font-size:12px;">( Để trống nếu không có điều kiện )</span></label>
            <span class="field">
				<textarea name="condition" style="width: 98%;" cols="80" rows="5" class="span5" placeholder="Điều kiện sử dụng"><?php echo $this->input->post('condition');?></textarea> 
			</span>
        </p>
        <p>
        	<label>Số lượng ( * )</label>
            <span class="field"><input type="number" name="amount" class="input-xlarge" placeholder="Số lượng" value="<?php echo $this->input->post('amount');?>"/></span>
        </p>
        <p>
        	<label>Đã sử dụng</label>
            <span class="field"><input type="number" name="amount_available" class="input-xlarge" placeholder="Đã sử dụng" value="<?php echo $this->input->post('amount_available');?>"/></span>
        </p>
        <p>
        	<label>Thời hạn sử dụng ( * )</label>
            <span class="field"><input id="datepicker" type="text" class="input-xlarge" value="<?php echo $this->input->post('date_user');?>" name="date_user" placeholder="Thời hạn sử dụng" /></span>
        </p> 
		
		<p style="display:none;">
        	<label>Mã Coupon khách hàng</label>
            <span class="field" style="padding-top: 5px;">
                <?php echo $render_coupon_qrcode->coupon;?>
                <!-- <input type="text" name="sale_off" id="coupon-customers" class="input-xlarge" placeholder="Mã coupon khách hàng" value="<?php echo $render_coupon_qrcode->coupon;?>"/>
                <span id="checkcode" style="display: none;cursor: pointer"><i class="iconsweets-magnifying"></i> Kiểm tra Mã</span> -->
            </span>
        </p>
        <p style="display:none;">
        	<label>Mã Coupon QrCode</label>
            <span class="field" style="padding-top: 5px;">
                <?php echo $render_coupon_qrcode->coupon_qr?>
            </span>
            <!-- <span class="field"><input type="text" name="sale_off" class="input-xlarge" placeholder="Mã coupon QrCode" value="<?php echo $render_coupon_qrcode->coupon_qr?>"/></span>  -->
        </p>
        <p style="display:none;">
        	<label>Ảnh QrCode</label>
            <span class="field">
                <img src="<?php echo $imgbase.$img_qrcode;?>" id="img_incens_show_" style="display: inline-block; vertical-align: middle;width: 100px;height: 95px;border: 1px solid #CCC;background: #CCC;" />
            </span>
        </p>
		
		<p>
		<label>Ảnh đại diện</label>
		<span class="field">
			<img src="" id="img_incens" style="display: inline-block; vertical-align: middle;width: 100px;height: 95px;border: 1px solid #CCC;background: #CCC;" />
			<input type="hidden" name="img_incens_hd_" id="img_incens_hd_" value="" />
			<input type="hidden" name="img_incens_verify" id="img_incens_verify" value="" />
			<input type="hidden" name="img_check" id="img_check" value="" />
			<input class="uniform-file" type="file" name="fileupload" id="img_incens_" onchange="convertimage('img_incens_', 'img_incens_hd_', 'img_incens', 'img_check');" value="" />
			( Ảnh jpg, Kích thước 260x260, tối đa 2Mb )
		</span>
	</p>
		
        <p>
        	<label>Mô tả ngắn ( * )</label>
            <span class="field">
                <textarea name="brief" style="width: 98%;" cols="80" rows="5" class="span5" placeholder="Mô tả ngắn"></textarea>
            </span>
        </p>
        <p>
        	<label>Nội dung</label>
            <span class="field"><textarea name="content" id="content" cols="80" rows="5" class="span5"></textarea></span>
        </p>
        <input type="hidden" name="count_slides" id="count_slides" value="" />
        <!-- <p>
        	<label>Chọn loại E-coupon</label>
            <span class="formwrapper">
           	 <input id="x1" type="radio" name="incentives_type" value="0" checked="checked"/> Cố định &nbsp; &nbsp;
           	 <input id="x2" type="radio" name="incentives_type" value="1" /> Hàng tháng
            </span>
        </p>
        <p id="time_select_box">
        	<label>Thời gian</label>
            <span class="field">
                <?php echo $fview->selectType($month, date('m'), 'sl_month');?>
                &nbsp;&nbsp;&nbsp;
                <?php echo $fview->selectType($year, date('Y'), 'sl_year');?>
            </span>
        </p> -->
        <p>
        	<label>Chọn đối tượng nhà hàng</label>
            <span class="formwrapper">
            	<input id="r1" type="radio" name="restaurant_target" value="0" checked="checked"/> Chọn tất cả &nbsp; &nbsp;
            	<input id="r2" type="radio" name="restaurant_target" value="1" /> Một hoặc nhiều nhà hàng
            </span>
        </p>
        <p id="restaurant_select_box">
        	<label>Lựa chọn nhà hàng</label>
            <span class="formwrapper">
                  <?php //echo $fview->multiSelectType($arrRestaurant, array(array('id' => 5), array('id' => 6)), 'restaurants', 'Chọn nhà hàng');?>
                  <?php echo $fview->multiSelectType($arrRestaurant, 0, 'restaurants', 'Chọn nhà hàng');?>
            </span>
        </p>
        <p>
        	<label>Trạng thái ( * )</label>
            <span class="field" style="position: relative;top: 5px;">
                <input type="checkbox" name="active" id="active" class="input-xlarge" placeholder="Trạng thái" <?php echo $this->input->post('active') == 1 ? 'checked="checked"' : '' ;?> value="1"/>
                Kích hoạt
            </span>
        </p>
        <p>
        	<label>Email subject ( * )</label>
            <span class="field" style="position: relative;top: 5px;">
                <input type="text" name="subject_email" id="subject_email" class="input-xlarge" placeholder="Subject Email" value="<?php echo $this->input->post('subject_email');?>"/>
            </span>
        </p>
        <p>
        	<label>Email tùy chỉnh - Lưu ý ( * )</label>
            <span class="field" style="position: relative;top: 5px;">
                <textarea name="note_email" id="note_email" cols="80" rows="5" class="span5"></textarea>
            </span>
        </p>
        <p>
            <label></label>
            <button class="btn btn-rounded" type="submit"> <i class="iconfa-ok"></i> &nbsp; Lưu</button>
        </p>
    </form>
    
    </div>
</div>

<script>

function convertimage(id, id_parse, img_show)
{
    var id = id;
    var id_parse = id_parse;
    var img_show = img_show;
    var filesSelected = document.getElementById(id).files;
    if (filesSelected.length > 0)
    {
        var fileToLoad = filesSelected[0];

        var fileReader = new FileReader();

        fileReader.onload = function(fileLoadedEvent) 
        {
            $("#"+id_parse).attr('value', fileLoadedEvent.target.result);
            //document.getElementById('cddd').html(fileLoadedEvent.target.result);
            $("#"+img_show).attr('src', fileLoadedEvent.target.result);
        };

        fileReader.readAsDataURL(fileToLoad);
    }
}
</script>


<script>


$(function()
{
    $('#time_select_box').hide();    
    $('input[type=radio][name=incentives_type]').change(function()
    {
        var type = this.value;
        
        if(type == 1){
            $('#time_select_box').fadeIn('slow');    
        }else{
            $('#time_select_box').fadeOut('slow');
        }
    });
    $('#restaurant_select_box').hide();
    $('input[type=radio][name=restaurant_target]').change(function()
    {
        var r_type = this.value;
        
        if(r_type == 1){
            $('#restaurant_select_box').fadeIn('slow');
        }else{
            $('#restaurant_select_box').fadeOut('slow');
        }
    });
    $("#coupon-customers").on('blur', function()
    {
        //$("#checkcode").css('display', 'block');
        $.ajax({
            type: "GET",
            url: '<?php echo $baseurl?>manage/ecoupon/get-ecoupon'  
        });
    });
});
</script>
<script type="text/javascript">
        CKEDITOR.replace( 'content', {  enterMode : CKEDITOR.ENTER_BR, shiftEnterMode : CKEDITOR.ENTER_BR } );
        CKEDITOR.replace( 'note_email', {  enterMode : CKEDITOR.ENTER_BR, shiftEnterMode : CKEDITOR.ENTER_BR } );
        CKEDITOR.on( 'instanceReady', function( ev )
        {
         ev.editor.dataProcessor.writer.setRules( 'br',
         {
            indent : false,
            breakBeforeOpen : false,
            breakAfterOpen : false,
            breakBeforeClose : false,
            breakAfterClose : false
  });
  });
</script>